<template>
	<div id='system' v-loading="loading">
		<div class="content-top">
			<span class="h1">需求审批</span>
			<!--<span class="h2">推广查询</span>-->
		</div>
		<div style="margin-top: 30px;">
			<el-form ref="form" :model="form" label-width="80px" :label-position="labelPosition">
				<el-row :gutter="30">
				  <el-col :span="8">
				  	<div class="grid-content bg-purple leftdiv">
				  		<h2  class="infod">用户信息</h2>
				  		<el-form-item label="姓名">
						    <el-input v-model="form.name" :disabled="true"></el-input>
						</el-form-item>
						<el-form-item label="性别">
						    <el-select v-model="value" placeholder="请选择" :disabled="true">
							    <el-option
							      v-for="item in form.options"
							      :key="item.value"
							      :label="item.label"
							      :value="item.value">
							    </el-option>
							</el-select>
						</el-form-item>
						<el-form-item label="身份证号">
						    <el-input v-model="form.card" :disabled="true"></el-input>
						</el-form-item>
						<el-form-item label="年龄">
						    <el-input v-model="form.age" :disabled="true"></el-input>
						</el-form-item>
						<el-form-item label="手机号">
						    <el-input v-model="form.tel" :disabled="true"></el-input>
						</el-form-item>
						<el-form-item label="电话年限">
						    <el-input v-model="form.years" :disabled="true"></el-input>
						</el-form-item>
						<el-form-item label="芝麻分">
						    <el-input v-model="form.city" :disabled="true"></el-input>
						</el-form-item>
						<el-form-item label="居住地址">
						    <el-input v-model="form.address" :disabled="true"></el-input>
						</el-form-item>
						<!--<el-form-item label="QQ">
						    <el-input v-model="form.qq" :disabled="true"></el-input>
						</el-form-item>-->
						<el-form-item label="微信">
						    <el-input v-model="form.wechat" :disabled="true"></el-input>
						</el-form-item>
				  	</div>
				  </el-col>
				  <el-col :span="8">
				  	<div class="grid-content bg-purple-light rightdiv">
				  		<h2 class="infod">需求信息</h2>
				  		<p class="total">还有 {{form.total}}  条需求未处理</p>
				  		<el-form-item label="借款额度">
						    <el-input v-model="form.limit" :disabled="true"></el-input>
						</el-form-item>
						<el-form-item label="审判结果">
						    <el-radio-group v-model="radio2">
							    <el-radio :label="4">拒绝</el-radio>
							    <el-radio :label="2">初审中</el-radio>
							</el-radio-group>
						</el-form-item>
						<p class="total">拒绝原因：</p>
						<div >
							<el-input type="textarea" v-model="desc"></el-input>
						</div>
						<el-button type="primary"style="margin-top: 20px;" @click="Result()">确定</el-button>
				  	</div>
				  </el-col>
				</el-row>
			</el-form>
		</div>
	</div>
</template>

<script>
	import apis from '../../../api/prouserApi'
	export default {
	name:'deNeeds',
    data() {
      return {
      	loading:false,
      	labelPosition:'left',//左对齐
      	form:{
      		total:0,//未处理多少条
      		name:'',//用户名
      		options:[
	      		{
	      			value: '男',
          			label: '男'
	      		},
	      		{
	      			value: '女',
          			label: '女'
	      		} 
      		],
      		card:'',//身份证
      		age:'',//年龄
      		years:'',//电话实名年限
      		city:'',//居住城市
      		address:'',//居住地址
      		qq:'',//QQ
      		wechat:'',//微信
      		limit:'',//额度
      		
      	},
      	id:"",
      	value: '',//性别
      	radio2: 2,//进度
      	desc:'',//原因
      	ProviderID:'',
      }
    },
    created() {
		this.ProviderID = sessionStorage.ProviderID
		this.getallotmodel(this.ProviderID)
	},
    methods: {
    	//获取实体
    	getallotmodel(id){
    		this.loading = true
    		this.desc=""
    		this.$axios.get(apis.getallotmodel+'/'+id).then(res=>{
    				this.form.name = ""
					this.value=""
					this.form.card=""
					this.form.age=""
					this.form.tel=""
					this.form.years=""
					this.form.city=""
					this.form.address=""
					this.form.qq = ""
					this.form.wechat=""
					this.form.limit=""
					this.form.total = 0
				if(res.data.isOK) {
					this.form.name = res.data.data.Member.CNName
					this.value = res.data.data.Member.Gender
					this.form.card = res.data.data.Member.CardID
					this.form.age = res.data.data.Member.Age
					this.form.tel = res.data.data.Member.Tel
					this.form.years = res.data.data.Member.TelYears
					this.form.city = res.data.data.Member.ZMScore
					this.form.address = res.data.data.Member.Address
					this.form.qq = res.data.data.Member.QQ
					this.form.wechat = res.data.data.Member.WX
					this.form.limit = res.data.data.DemandMoney
					this.id = res.data.data.AllotID
					this.form.total = this.form.total || res.data.data.UnAllotAmount
					this.loading = false
				} else {
					if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
						this.$router.push({
							path: '/'
						})
					} else {
						this.loading = false
						this.$message.error(res.data.msg);
					}
				}
			})
    	},
    	//结果
    	Result(){
    		if(this.form.total<=0){
    			this.$message.error('没有未处理的');
    			return false;
    		}
    		this.loading = true
			this.$axios.post(apis.setallot,{
			  "AllotID": this.id,
			  "Status": this.radio2,
			  "RefuseMemo":this.desc
			}).then(res=>{
				if(res.data.isOK) {
					this.loading = false
					this.getallotmodel(this.ProviderID)
				} else {
					if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
						this.$router.push({
							path: '/'
						})
					} else {
						this.loading = false
						this.$message.error(res.data.msg);
					}
				}
			})
    	}
    }
  }
</script>

<style>
	.infod{
		margin-bottom: 20px;
	}
	.total{
		height: 40px;
		line-height: 40px;
		margin-bottom: 22px;
	}
	.leftdiv{
		background: #fff;
		padding: 15px;
		border: 1px solid #ccc;
	}
	.rightdiv{
		background: #fff;
		padding: 15px;
		border: 1px solid #ccc;
	}
</style>